
package com.uduew.sjd.ui.adapter;

import android.content.Context;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.uduew.sjd.R;
import com.uduew.sjd.api.AllLoanOrdersApi;
import com.uduew.sjd.databinding.LayoutRepaymentBinding;
import com.uduew.sjd.utils.DiffUtils;
import com.kunminx.binding_recyclerview.adapter.SimpleDataBindingAdapter;


public class RepaymentAdapter extends SimpleDataBindingAdapter<AllLoanOrdersApi.ResAllLoanOrdersBean.MamaguyBean.ThoroughBean, LayoutRepaymentBinding> {
    public RepaymentAdapter(Context context) {
        super(context, R.layout.layout_repayment, DiffUtils.getInstance().getLoanItemCallback());
    }

    @Override
    protected void onBindItem(LayoutRepaymentBinding binding, AllLoanOrdersApi.ResAllLoanOrdersBean.MamaguyBean.ThoroughBean item, RecyclerView.ViewHolder holder) {
        binding.setList(item);
        binding.tvViewDetail.setOnClickListener(v -> {
            if (mItemDetailClickListener != null) {
                mItemDetailClickListener.onItemDetailClick(item, holder.getLayoutPosition());
            }
        });
        binding.tvRollOverRepayment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mItemDetailClickListener != null) {
                    mItemDetailClickListener.onItemExtensionClick(item, holder.getLayoutPosition());
                }
            }
        });

        binding.tvGotoRepayment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mItemDetailClickListener != null) {
                    mItemDetailClickListener.onItemRepaymentClick(item, holder.getLayoutPosition());
                }
            }
        });

    }

    private OnItemDetailClickListener mItemDetailClickListener;

    public void setOnDetailClickListener(OnItemDetailClickListener l) {
        this.mItemDetailClickListener = l;
    }

    public interface OnItemDetailClickListener {

        void onItemDetailClick(AllLoanOrdersApi.ResAllLoanOrdersBean.MamaguyBean.ThoroughBean bean, int position);
        void onItemRepaymentClick(AllLoanOrdersApi.ResAllLoanOrdersBean.MamaguyBean.ThoroughBean bean, int position);
        void onItemExtensionClick(AllLoanOrdersApi.ResAllLoanOrdersBean.MamaguyBean.ThoroughBean bean, int position);


    }
}
